<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form id="f1">
        <input type="text" id="username"/>
        <input type="password" id="pwd"/>
        <input type="submit" value="注册" id="sub"/>
    </form>
</body>
<script>
    var f1 = document.getElementById("f1");
    var username = document.getElementById("username");
    var pwd = document.getElementById("pwd");
    var sub = document.getElementById("sub");


    username.onblur = function(){
        var val = username.value;
        if(val.length < 3){
            alert("用户名过短");
        }
    }

    pwd.onfocus = function(){
        console.log("获得焦点");
    }

    f1.onsubmit = function(){
        alert("表单提交");
    }

    /**
     * 1、function funName（x,y）{……}
     * 形参与实参的个数可以不一样funName(x,y,z);funName(x);
     * 2、(function(username){
     *       console.log(username);
     *    })("zhangsan");
     * 
     * var add = function(x,y){
     *      return x + y;
     * }
     * add(1,2);
     * 
     * dom object.eventName = function(){}
     * 常用时间：onclick、onmouseover、onmouseout、onblur、onfocus、onsubmit、onselect……
    */
</script>
</html>